<?php $this->load->view("include/meta"); ?>
    <title>我的活动-打球吧</title>

    <!-- Bootstrap core CSS -->
    <link href="<?php echo site_url();?>assets/css/bootstrap.css" rel="stylesheet">
    <link href="<?php echo site_url();?>assets/css/common.css" rel="stylesheet">
    <link href="<?php echo site_url();?>assets/css/user.css" rel="stylesheet">
    <link href="<?php echo site_url();?>assets/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <link href="<?php echo site_url();?>assets/css/jquery-impromptu.css" rel="stylesheet">

  </head>

  <body>

    <!-- Wrap all page content here -->
    <div id="wrap">

    <!-- header start -->
    <?php $this->load->view("include/header"); ?> 
    <!-- header end -->

    <div class="container" id="main">

        <div class="row" id="fillin">
            <div class="col-md-6 col-md-push-6">

             <div class="list-group">
                <?php if(empty($threads)) : ?>
                    <?php if($self) : ?>
                <div class="list-group-item list-group-item-title">还没发起过活动，<a href="<?php echo site_url('activity/add/');?>">点击这里</a>马上发起活动</div>
                    <?php else : ?>
                <div class="list-group-item list-group-item-title"><?php echo $userInfo['gender'] == 1 ? '他':'她';?>还没发起过活动</div>
                    <?php endif; ?>
                <?php else : ?>
                    <?php if($self) : ?>
                <div class="list-group-item list-group-item-title">我发起的活动</div>
                    <?php else : ?>
                <div class="list-group-item list-group-item-title"><?php echo $userInfo['gender'] == 1 ? '他':'她';?>发起的活动</div>
                    <?php endif; ?>
                <?php endif; ?>
                <?php foreach ($threads as $item):?>
                <a class="list-group-item" href="<?php echo site_url('activity').'/?tid='.$item['tid'] ;?>" target="_blank"><?php echo $item['subject'];?> [<?php echo date('Y-m-d',strtotime($item['dateline']));?>发起]</a>
                <?php endforeach; ?>
              </div>                    
                
             <?php if($next): ?>
             <ul id="pager" class="pager">
               <li><a href="javascript:;">更早的</a></li>
             </ul>
             <?php endif; ?>

            </div>

            <div class="col-md-6 col-md-pull-6">

                <div class="panel panel-default">
                  <div class="panel-body">

                    <ul class="nav nav-tabs">
                      <li class="active"><a href="#profile" data-toggle="tab"><?php if($self):?>我的<?php else:?><?php echo $userInfo['gender'] == 1 ? '他':'她';?>的<?php endif;?>信息</a></li>
                      <?php if($self) : ?>
                      <li><a href="#settings" data-toggle="tab">修改密码</a></li>
                      <?php endif; ?>
                    </ul>

                    <div class="tab-content margin-top-10">

                      <div class="tab-pane active" id="profile">

                        <table class="table">
                            <tbody>
                              <?php if($self): ?>
                              <tr>
                                <td>帐号</td>
                                <td><?php echo $userInfo['email'];?> <span id="setting" class="glyphicon glyphicon-cog setting"></span></td>
                              </tr>
                              <?php endif;?>
                              <tr>
                                <td>昵称</td>
                                <td><?php echo $userInfo['username'];?></td>
                              </tr>
                              <!--
                              <tr>
                                <td>信用</td>
                                <td><?php echo $userInfo['score'];?></td>
                              </tr>
                              -->
                              <tr>
                                <td>性别</td>
                                <td><?php echo $userInfo['gender'] == 1 ? '男':'女';?></td>
                              </tr>
                              <tr>
                                <td>年龄</td>
                                <td><?php echo $userInfo['birthday'] == '0000-00-00' ? '未知' : getAgeByBirthday($userInfo['birthday']);?></td>
                              </tr>
                              <tr>
                                <td>身高</td>
                                <td><?php echo $userInfo['height'] ? $userInfo['height'] : '未知';?></td>
                              </tr>
                            </tbody>
                          </table>

                      </div>

                      <div class="tab-pane" id="settings">

                          <div class="col-lg-8">
                              <input type="password" placeholder="原密码" name="oldPassword" class="form-control" maxLength="10" autocomplete="off" maxLength="30" />
                          </div>

                          <div class="col-lg-8 margin-top-10">
                              <input type="password" placeholder="新密码；2到10个字符噢" name="newPassword" class="form-control" maxLength="10" autocomplete="off" maxLength="30"/>
                          </div>

                          <div class="col-lg-8 margin-top-10">
                              <input type="password" placeholder="重复新密码" name="rePassword" class="form-control" maxLength="10" autocomplete="off" maxLength="30" />
                          </div>

                          <div class="col-lg-8 margin-top-10">
                            <button class="btn btn-info" type="button" id="changePassword">修改密码</button>
                          </div>
                      </div>

                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog">
                        <div class="modal-content">
                          <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">修改个人信息</h4>
                          </div>
                          <div class="modal-body">

                            <div role="form">
                              <div class="form-group">
                                <label style="display:block;">性别</label>
                                <input type="radio" name="gender" value="1" <?php echo $userInfo['gender'] == 1 ? 'checked' : '';?>>男
                                <input type="radio" name="gender" value="2" <?php echo $userInfo['gender'] != 1 ? 'checked' : '';?>>女
                              </div>
                              <div class="form-group">
                                <label>出生年月</label>
                                <input type="text" value="<?php echo $userInfo['birthday'] == '0000-00-00'? '' : $userInfo['birthday']; ?>" id="datetimepicker" name="birthday" class="form-control" readonly />
                              </div>
                              <div class="form-group">
                                <label>身高</label>
                                <input type="text" value="<?php echo $userInfo['height'] ? $userInfo['height']:'175'; ?>" name="height" class="form-control" maxLength="3" autocomplete="off" />
                              </div>
                            </div>

                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-primary" id="modify">确认修改</button>
                          </div>
                        </div><!-- /.modal-content -->
                      </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    </div>

                  </div>
                </div>
 
            </div>

        </div>
    </div>    <!-- end content -->

    </div>    <!-- end wrap -->

    <!-- footer start -->
    <?php $this->load->view("include/footer"); ?> 
    <!-- footer end -->

    <script type="text/javascript" src="<?php echo site_url();?>assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="<?php echo site_url();?>assets/js/jquery-impromptu.js"></script>
    <script type="text/javascript" src="<?php echo site_url();?>assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<?php echo site_url();?>assets/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="<?php echo site_url();?>assets/js/bootstrap-datetimepicker.zh-CN.js" ></script>
    <script type="text/javascript">
    $(function(){

        <?php if($next): ?>
        var from  = <?php echo $num-1;?>;
        var limit = <?php echo $num;?>;

        $('#pager').find('a').click(function(){
            $.ajax({
                url: "<?php echo site_url();?>api/user/getMyActivity",
                type: "GET",
                dataType: "json",
                data:{fid:0,from:from,limit:limit,authorid:'<?php echo $userInfo['uid'];?>'},
                success: function(data){
                    //最后一项不取
                    for(var i=0;i<limit-1;i++)
                    {
                        if(data.data[i])
                        {
                            var html = '<a class="list-group-item" href="<?php echo site_url("activity");?>/?tid='+data.data[i]['tid']+'" target="_blank">'+data.data[i]["subject"]+'['+data.data[i]['dateline'].substring(0,10)+'发起]</a>';
                            $('#fillin').find('div.list-group').append(html);
                        }
                    }

                    if(data.data.length < limit)
                    {
                        $('#pager').hide();
                    }
                }
            });

            from+=limit-1;
        });
        <?php endif; ?>

        <?php if($self) : ?>
        //初始化时间控件
        $("#datetimepicker").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            startDate: '1950-01-01',
            endDate: '2010-12-31',
            autoclose: true,
            startView:4,
            language:'zh-CN',
            showMeridian:false,
            todayBtn: false 
        });


        $('#setting').click(function()
        {
            $('#myModal').modal();
        });

        $('#changePassword').click(function(){
            
            if($('input[name="oldPassword"]').val().length < 6 || $('input[name="rePassword"]').val().length < 6)
            {
                $.prompt('密码需大于六位',{
                        buttons: { "确定": true },
                        fitMasker: true
                        });
                return false;
            }

            if($('input[name="newPassword"]').val() != $('input[name="rePassword"]').val())
            {
                $.prompt('重复密码不一致',{
                        buttons: { "确定": true },
                        fitMasker: true
                        });
                return false;
            }

            $.ajax({
                url: "<?php echo site_url();?>api/user/changePassword",
                type: "POST",
                dataType: "json",
                data: {oldPassword:$('input[name="oldPassword"]').val(),newPassword:$('input[name="newPassword"]').val(),rePassword:$('input[name="rePassword"]').val()},
                success: function(data){

                    if(data.error == 0)
                    {
                        $.prompt('修改成功',{
                                buttons: { "确定": true },
                                fitMasker: true,
                                isButtonHide:true
                                });
                        setTimeout(function(){$.prompt.close();window.location.reload();},2000);
                    }
                    else
                    {
                        $.prompt(data.msg,{
                                buttons: { "确定": true },
                                fitMasker: true
                                });

                        return false;

                    }

                }
            });
        });

        $('#modify').click(function(){
            var height = $('input[name="height"]').val();

            if( parseInt(height) != height || height < 150 || height > 200)
            {
                $('#myModal').modal('hide')

                $.prompt('请填写正确的身高数据',{
                        buttons: { "确定": true },
                        fitMasker: true
                        });

                return false;
            }

            $.ajax({
                url: "<?php echo site_url();?>api/user/setUserDetail",
                type: "POST",
                dataType: "json",
                data:{gender:$('input[name="gender"]:checked').val(),birthday:$('input[name="birthday"]').val(),height:$('input[name="height"]').val(),area:'',player_type:0}, 
                success: function(data){

                    $('#myModal').modal('hide')

                    if(data.error == 0)
                    {
                        $.prompt('修改成功',{
                                buttons: { "确定": true },
                                fitMasker: true,
                                isButtonHide:true
                                });
                        setTimeout(function(){$.prompt.close();window.location.reload();},2000);
                    }
                    else
                    {
                        $.prompt(data.msg,{
                                buttons: { "确定": true },
                                fitMasker: true
                                });

                        return false;

                    }
                }
            });

        });
        <?php endif;?>
    });
    </script>

    </body>
</html>
